package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

type CM_CORP_CUST_DIM struct {
	ID       int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	Sfktwy   string     `gorm:"column:是否开通网银;"`
	Ktwybbzl string     `gorm:"column:开通网银版本种类;"`
	KHMC     string     `gorm:"column:客户名称"`
	Zzkhrq   *time.Time `gorm:"column:最早开户日期;type:date;"`
	Zzjgdm   string     `gorm:"column:组织机构代码;"`
	Yyzz     string     `gorm:"column:营业执照;"`
	Swzh     string     `gorm:"column:税务证号;"`
	Qygmhb   string     `gorm:"column:企业规模行标;"`
	Qygmgj   string     `gorm:"column:企业规模国标;"`
	Xhyzldm  string     `gorm:"column:新行业种类代码;"`
	Sfjsh    string     `gorm:"column:是否结算户;"`
	ISDKH    bool       `gorm:"column:ISDKH"`
	ISYXH    bool       `gorm:"column:ISYXH"`
	ISJGH    bool       `gorm:"column:ISJGH"`
	ISJBH    bool       `gorm:"column:ISJBH"`
	SXJE     float64    `gorm:"column:SXJE"`
	CUID     int        `gorm:"column:CUID"`
	YG1      string     `gorm:"-"`
	ZB1      *float64   `gorm:"-"`
	YG2      string     `gorm:"-"`
	ZB2      *float64   `gorm:"-"`
	YG3      string     `gorm:"-"`
	ZB3      *float64   `gorm:"-"`
	YG4      string     `gorm:"-"`
	ZB4      *float64   `gorm:"-"`
	YG5      string     `gorm:"-"`
	ZB5      *float64   `gorm:"-"`
}

//TableName 卡号表名
func (CM_CORP_CUST_DIM) TableName() string {
	return "V_CM_CORP_CUST_DIM"

}

func (c *CM_CORP_CUST_DIM) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_clie_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
	if err != nil {
		return
	}
	i := 0
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

//CM_CORP_CUST_DIM 对公客户信息
func CM_CORP_CUST_DIMEF() base.EntityFunc {
	return func() interface{} {
		entity := CM_CORP_CUST_DIM{}
		return &entity
	}
}

//CM_CORP_CUST_DIM 对公客户信息
func CM_CORP_CUST_DIMESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CM_CORP_CUST_DIM
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(CM_CORP_CUST_DIMEF(), CM_CORP_CUST_DIMESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "CUID",
		TableName:     "T_COMP_CLIE_YGFC",
		EmidColName:   "emid",
		AcidColName:   "CUID",
		WhereCause:    "DTID=dbo.GetDateToInt(dbo.GetCurSysDate())",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("CM_CORP_CUST_DIM", dao)
}
